/*
 * @# PhotosLikesController.java 2011-12-31 上午10:14:26
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.px.album.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ianswer.common.util.Feedback;
import com.ianswer.px.album.entity.PhotoLike;
import com.ianswer.px.album.service.PhotoLikeService;
import com.ianswer.px.common.SessionContextHolder;
import com.ianswer.px.common.annotation.SessionAware;

/**
 * @author alvin hwang
 */
@SessionAware
@Controller
public class PhotosLikesController {

	@Resource(name = "photoLikeService")
	private PhotoLikeService photoLikeService;

	@RequestMapping(value = "/albums/{albumId}/photos/{photoId}/likes", method = RequestMethod.GET)
	public @ResponseBody List<PhotoLike> likes(@PathVariable("albumId") Long albumId, @PathVariable("photoId") Long photoId) {
		return photoLikeService.queryFirstPage(photoId);
	}

	@RequestMapping(value = "/albums/{albumId}/photos/{photoId}/likes/create", method = RequestMethod.POST)
	public @ResponseBody Feedback createLikes(@PathVariable("albumId") Long albumId, @PathVariable("photoId") Long photoId) {
		Long userId = SessionContextHolder.getUserId();
		photoLikeService.insert(albumId, photoId, userId);
		return Feedback.success("t");
	}
}
